package com.demo2do.fms.admin.web.controller.authority.role;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.entity.page.Page;
import com.demo2do.core.web.interceptor.MenuSetting;
import com.demo2do.fms.admin.service.authority.ResourceService;
import com.demo2do.fms.entity.authority.Resource;

/**
 * 资源管理
 * 
 * @author Ysy
 *
 */
@Controller
@RequestMapping("/resources")
@MenuSetting("menu-authority")
public class ResourceController {
    
    @Autowired
    private ResourceService resourceService;

    /**
     * 列表
     * 
     * @param page
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.GET)
    @MenuSetting("submenu-resource-management")
    public ModelAndView list(Page page){
        
        ModelAndView modelAndView = new ModelAndView("authority/resource/resource-list");
        
        int totals = resourceService.count(Resource.class);
        if(totals > 0){
            
            List<Resource> resources = resourceService.listByPage(Resource.class, page.with(totals));
            
            modelAndView.addObject("resources", resources);
            modelAndView.addObject("page", page);
        }
        
        return modelAndView;
        
    }
    
}
